/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HoofdPagina.java
 *
 * Created on 17-mrt-2011, 11:29:06
 */
package view;

import connections.Query;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import main.ApplicatieMain;

/**
 *
 * @author Jeroen
 */
public class KlassenBeheerPagina extends javax.swing.JPanel {

    private Query query;
    private ApplicatieMain applicatieMain;
    private List<String> klassenLijst;
    private List<String> leerlingLijst;

    /** Creates new form HoofdPagina */
    public KlassenBeheerPagina() {
        applicatieMain = ApplicatieMain.getInstance();
        query = applicatieMain.getQuery();

        initComponents();
        applicatieMain.setKlasBeheer(this);
        initKlassenLijst();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel7 = new javax.swing.JPanel();
        lblKiesKlas = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listKlassen = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        listLeerlingen = new javax.swing.JList();
        lblKiesLeerling = new javax.swing.JLabel();
        lblKlas = new javax.swing.JLabel();
        lblKlasNaam = new javax.swing.JLabel();
        lblLeerlingNaam = new javax.swing.JLabel();
        btnVoegKlasToe = new javax.swing.JButton();
        btnVoegLeerlingToe = new javax.swing.JButton();
        btnWoordenLijst = new javax.swing.JButton();
        lblDeleteKlas = new javax.swing.JLabel();
        lblDeleteLeerling = new javax.swing.JLabel();
        btnLogOff = new javax.swing.JButton();
        lblEditKlas = new javax.swing.JLabel();
        lblEditLeerling = new javax.swing.JLabel();
        lblLeerlingMove = new javax.swing.JLabel();
        btnBekijkProfiel = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();

        setBackground(new java.awt.Color(255, 255, 255));
        setPreferredSize(new java.awt.Dimension(1219, 502));

        jPanel7.setBackground(new java.awt.Color(255, 255, 255));
        jPanel7.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(183, 234, 0), 10, true));

        lblKiesKlas.setText("Kies een klas:");

        listKlassen.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listKlassenValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(listKlassen);

        listLeerlingen.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listLeerlingenValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(listLeerlingen);

        lblKiesLeerling.setText("Kies een leerling:");

        lblKlas.setFont(new java.awt.Font("Tahoma", 0, 14));
        lblKlas.setText("Klas:");

        btnVoegKlasToe.setText("Voeg klas toe");
        btnVoegKlasToe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVoegKlasToeActionPerformed(evt);
            }
        });

        btnVoegLeerlingToe.setText("Voeg leerling toe");
        btnVoegLeerlingToe.setEnabled(false);
        btnVoegLeerlingToe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVoegLeerlingToe(evt);
            }
        });

        btnWoordenLijst.setText("Woordenlijst Beheer");
        btnWoordenLijst.setEnabled(false);
        btnWoordenLijst.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnWoordenLijstActionPerformed(evt);
            }
        });

        lblDeleteKlas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/delete.png"))); // NOI18N
        lblDeleteKlas.setToolTipText("Verwijder de klas");
        lblDeleteKlas.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblDeleteKlas.setEnabled(false);
        lblDeleteKlas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblDeleteKlasMouseClicked(evt);
            }
        });

        lblDeleteLeerling.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/delete.png"))); // NOI18N
        lblDeleteLeerling.setToolTipText("Verwijder de leerling");
        lblDeleteLeerling.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblDeleteLeerling.setEnabled(false);
        lblDeleteLeerling.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblDeleteLeerlingMouseClicked(evt);
            }
        });

        btnLogOff.setText("Log uit");
        btnLogOff.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLogOffActionPerformed(evt);
            }
        });

        lblEditKlas.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/modifyIcon.gif"))); // NOI18N
        lblEditKlas.setToolTipText("Verander de naam van de klas");
        lblEditKlas.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblEditKlas.setEnabled(false);
        lblEditKlas.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblEditKlasMouseClicked(evt);
            }
        });

        lblEditLeerling.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/modifyIcon.gif"))); // NOI18N
        lblEditLeerling.setToolTipText("Verander de naam van de leerling");
        lblEditLeerling.setAlignmentY(0.0F);
        lblEditLeerling.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblEditLeerling.setEnabled(false);
        lblEditLeerling.setIconTextGap(0);
        lblEditLeerling.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblEditLeerlingMouseClicked(evt);
            }
        });

        lblLeerlingMove.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/moveIcon.gif"))); // NOI18N
        lblLeerlingMove.setToolTipText("Verplaats leerling naar een andere klas");
        lblLeerlingMove.setAlignmentY(0.0F);
        lblLeerlingMove.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        lblLeerlingMove.setEnabled(false);
        lblLeerlingMove.setIconTextGap(0);
        lblLeerlingMove.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblLeerlingMoveMouseClicked(evt);
            }
        });

        btnBekijkProfiel.setText("Bekijk profiel");
        btnBekijkProfiel.setEnabled(false);
        btnBekijkProfiel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBekijkProfielActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(lblKiesKlas)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(lblEditKlas)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblDeleteKlas)))
                .addGap(74, 74, 74)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(lblKiesLeerling)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(lblEditLeerling)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblLeerlingMove, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblDeleteLeerling))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(btnBekijkProfiel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnWoordenLijst, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnVoegLeerlingToe, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btnLogOff, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel7Layout.createSequentialGroup()
                            .addComponent(lblKlas)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 101, Short.MAX_VALUE))
                        .addComponent(btnVoegKlasToe, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)))
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblLeerlingNaam, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
                    .addComponent(lblKlasNaam, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDeleteLeerling)
                    .addComponent(lblEditKlas)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblKiesKlas)
                            .addComponent(lblKiesLeerling)
                            .addComponent(lblDeleteKlas)))
                    .addComponent(lblLeerlingMove)
                    .addComponent(lblEditLeerling))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblKlas)
                            .addComponent(lblKlasNaam, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel7Layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(lblLeerlingNaam, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel7Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnVoegKlasToe)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBekijkProfiel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnVoegLeerlingToe)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnWoordenLijst)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnLogOff))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 617, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 87, Short.MAX_VALUE)
        );

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 206, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 502, Short.MAX_VALUE)
        );

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 674, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 83, Short.MAX_VALUE)
        );

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 206, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 502, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void listKlassenValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listKlassenValueChanged
        if (listKlassen.getSelectedIndex() != - 1) {
            btnVoegLeerlingToe.setEnabled(true);
            lblDeleteKlas.setEnabled(true);
            lblEditKlas.setEnabled(true);
            btnWoordenLijst.setEnabled(true);
        } else {
            lblDeleteKlas.setEnabled(false);
            lblEditKlas.setEnabled(false);
            btnVoegLeerlingToe.setEnabled(false);
            btnWoordenLijst.setEnabled(false);
        }
        initLeerlingLijst();
    }//GEN-LAST:event_listKlassenValueChanged

    private void btnVoegKlasToeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVoegKlasToeActionPerformed

        String nieuweKlasNaam = JOptionPane.showInputDialog(this, "Naam klas", "Klas toevoegen", JOptionPane.INFORMATION_MESSAGE);
        if (!nieuweKlasNaam.equals("")) {
            if (query.getKlasID(nieuweKlasNaam) != -1) {
                JOptionPane.showConfirmDialog(this, "Klas \"" + nieuweKlasNaam + "\" bestaat al.",
                        "Fout", JOptionPane.DEFAULT_OPTION);
            } else {
                query.addKlas(nieuweKlasNaam);
                initKlassenLijst();
            }

        }
        
    }//GEN-LAST:event_btnVoegKlasToeActionPerformed

    private void listLeerlingenValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listLeerlingenValueChanged
        if (listLeerlingen.getSelectedIndex() != -1) {
            btnBekijkProfiel.setEnabled(true);
            lblDeleteLeerling.setEnabled(true);
            lblEditLeerling.setEnabled(true);
            lblLeerlingMove.setEnabled(true);
            lblLeerlingNaam.setText(leerlingLijst.get(listLeerlingen.getSelectedIndex()));
        } else {
            btnBekijkProfiel.setEnabled(false);
            lblLeerlingNaam.setText("");
            lblDeleteLeerling.setEnabled(false);
            lblEditLeerling.setEnabled(false);
            lblLeerlingMove.setEnabled(false);
        }
    }//GEN-LAST:event_listLeerlingenValueChanged
    private void btnWoordenLijstActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnWoordenLijstActionPerformed
        applicatieMain.setSelectedKlasID(query.getKlasID(klassenLijst.get(listKlassen.getSelectedIndex())));
        applicatieMain.showPage(new view.WoordenlijstBeheer());
    }//GEN-LAST:event_btnWoordenLijstActionPerformed

    private void btnVoegLeerlingToe(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVoegLeerlingToe
        String nieuweLeerlingNaam = JOptionPane.showInputDialog(this, "Naam Leerling", "Leerling toevoegen", JOptionPane.INFORMATION_MESSAGE);
        if (!nieuweLeerlingNaam.equals("")) {
            if (query.getLeerlingID(klassenLijst.get(listKlassen.getSelectedIndex()), nieuweLeerlingNaam) != -1) {
                JOptionPane.showConfirmDialog(this, "Leerling \"" + nieuweLeerlingNaam + "\" bestaat al.",
                        "Fout", JOptionPane.DEFAULT_OPTION);
            } else {
                query.addLeerling(klassenLijst.get(listKlassen.getSelectedIndex()), nieuweLeerlingNaam);
                initLeerlingLijst();
            }
        }
        
    }//GEN-LAST:event_btnVoegLeerlingToe

    private void lblDeleteKlasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblDeleteKlasMouseClicked
        if (listKlassen.getSelectedIndex() != -1) {
            query.deleteKlas(klassenLijst.get(listKlassen.getSelectedIndex()), applicatieMain.getBrinNummer());
            initKlassenLijst();
        }
    }//GEN-LAST:event_lblDeleteKlasMouseClicked

    private void lblDeleteLeerlingMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblDeleteLeerlingMouseClicked
        if (listLeerlingen.getSelectedIndex() != -1) {
            query.deleteLeerling(
                    leerlingLijst.get(listLeerlingen.getSelectedIndex()),
                    applicatieMain.getBrinNummer(),
                    klassenLijst.get(listKlassen.getSelectedIndex()));
            initLeerlingLijst();
        }
    }//GEN-LAST:event_lblDeleteLeerlingMouseClicked

    private void btnLogOffActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLogOffActionPerformed
        applicatieMain.showPage(new view.KlassenBeheerLogin());
    }//GEN-LAST:event_btnLogOffActionPerformed

    private void lblLeerlingMoveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblLeerlingMoveMouseClicked
        JFrame frame = new view.KlassenBeheerMove((String)leerlingLijst.get(listLeerlingen.getSelectedIndex()));
        frame.setVisible(true);
    }//GEN-LAST:event_lblLeerlingMoveMouseClicked

    private void lblEditLeerlingMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblEditLeerlingMouseClicked
        String leerlingNaam = JOptionPane.showInputDialog(this, "Naam leerling", "Leerling naam veranderen", JOptionPane.INFORMATION_MESSAGE);
        if (leerlingNaam != null) {
            if (query.getKlasID(leerlingNaam) != -1) {
                JOptionPane.showConfirmDialog(this, "Leerling \"" + leerlingNaam + "\" bestaat al.",
                        "Fout", JOptionPane.DEFAULT_OPTION);
            } else {
                query.userChangeName((String)listLeerlingen.getSelectedValue(), leerlingNaam);
            }
        }
        initLeerlingLijst();
    }//GEN-LAST:event_lblEditLeerlingMouseClicked

    private void lblEditKlasMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblEditKlasMouseClicked
        String klasNaam = JOptionPane.showInputDialog(this, "Naam klas", "Klas naam veranderen", JOptionPane.INFORMATION_MESSAGE);
        if (klasNaam != null) {
            if (query.getKlasID(klasNaam) != -1) {
                JOptionPane.showConfirmDialog(this, "Klas \"" + klasNaam + "\" bestaat al.",
                        "Fout", JOptionPane.DEFAULT_OPTION);
            } else {
                query.klasChangeName((String)listKlassen.getSelectedValue(), klasNaam);
            }
        }
        initKlassenLijst();
        listLeerlingen.setListData(new Object[0]);
    }//GEN-LAST:event_lblEditKlasMouseClicked

    private void btnBekijkProfielActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBekijkProfielActionPerformed
        applicatieMain.setUsername(listLeerlingen.getSelectedValue().toString());
        System.out.println("Haalt uit lijst: "+listLeerlingen.getSelectedValue().toString());
        System.out.println("Gets: "+applicatieMain.getUsername());
        applicatieMain.showPage(new view.ProfilePage());
    }//GEN-LAST:event_btnBekijkProfielActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBekijkProfiel;
    private javax.swing.JButton btnLogOff;
    private javax.swing.JButton btnVoegKlasToe;
    private javax.swing.JButton btnVoegLeerlingToe;
    private javax.swing.JButton btnWoordenLijst;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblDeleteKlas;
    private javax.swing.JLabel lblDeleteLeerling;
    private javax.swing.JLabel lblEditKlas;
    private javax.swing.JLabel lblEditLeerling;
    private javax.swing.JLabel lblKiesKlas;
    private javax.swing.JLabel lblKiesLeerling;
    private javax.swing.JLabel lblKlas;
    private javax.swing.JLabel lblKlasNaam;
    private javax.swing.JLabel lblLeerlingMove;
    private javax.swing.JLabel lblLeerlingNaam;
    private javax.swing.JList listKlassen;
    private javax.swing.JList listLeerlingen;
    // End of variables declaration//GEN-END:variables

    public void initKlassenLijst() {
        klassenLijst = query.getKlassenLijst(applicatieMain.getBrinNummer());
        listKlassen.setListData(klassenLijst.toArray());

    }

    public void initLeerlingLijst() {
        if (listKlassen.getSelectedIndex() != -1) {
            String klas = klassenLijst.get(listKlassen.getSelectedIndex());
            leerlingLijst = query.getLeerlingLijst(applicatieMain.getBrinNummer(), klas);
            listLeerlingen.setListData(leerlingLijst.toArray());
            lblKlasNaam.setText(klas);
            lblLeerlingNaam.setText("");
        } else {
            listLeerlingen.clearSelection();
            listLeerlingen.setListData(new Object[0]);
            lblKlasNaam.setText("");
            lblLeerlingNaam.setText("");
        }

    }
}
